package com.keqiang.kq_flutter_tv_widgets;

import com.keqiang.kq_flutter_tv_widgets.channel.NativeScanChannel;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;

/**
 * KqFlutterTvWidgetsPlugin
 */
public class KqFlutterTvWidgetsPlugin implements FlutterPlugin, ActivityAware {
    /// The MethodChannel that will the communication between Flutter and native Android
    ///
    /// This local reference serves to register the plugin with the Flutter Engine and unregister it
    /// when the Flutter Engine is detached from the Activity
    
    private NativeScanChannel mScanChannel;
    
    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
        mScanChannel = new NativeScanChannel(flutterPluginBinding.getBinaryMessenger());
    }
    
    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
        mScanChannel.setMethodCallHandler(null);
    }
    
    @Override
    public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
        if (mScanChannel != null) {
            mScanChannel.setContext(binding.getActivity());
        }
    }
    
    @Override
    public void onDetachedFromActivityForConfigChanges() {
    
    }
    
    @Override
    public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
    
    }
    
    @Override
    public void onDetachedFromActivity() {
    
    }
}
